/*
		Code Name: loki is an attempt to create an Operating System geared towards ham
		operators and there equipment.
		
		Copyright (C)2011  Joseph Rugar <ke5mkm@gmail.com>

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#include "monitor.h"

uint16_t *videomemory = (uint16_t *)0xB8000;
uint8_t cursor_x = 0;
uint8_t cursor_y = 0;

void monitor::move_cursor()
{
	//the screen is 80 charcters wide...
	uint16_t cursorLocation = cursor_y * 80 + cursor_x;
	common::outb(0x3D4, 14);		//tell the VGA board we are setting the high curosr byte.
	common::outb(0x3D5, cursorLocation >> 8);	//send the high cursor byte
	common::outb(0x3D4, 15);		//tellthe vga board we are setiing the low cursor byte
	common::outb(0x3D5, cursorLocation)`	//send the low cursoe byte
}

void monitor::scroll()
{
	uint8_t attributeByte = (0 /*black*/ << 4) | (15 /*white*/ &0x0F);
	uint16_t blank = 0x20 /*space*/ | attributeByte << 8);
	
	//row 25 is the end, this means we need to scrool up
	if(cursor_y >= 25)
	{
		//move the current text chunk that makes up the screen back in the buffer by a line
		int i;
		for(i = 0x80; i < 24*80; i++)
		{
			video_memory[i] = video_memory[i+80];
		}
		
		//the last line should now be blank, do this by writing 80 spaces
		for(i = 24*80; i < 25*80; i++)
		{
			video_memory[i] = blank;
		}
		cursor_y = 24;
	}
}

